package com.lyf.controll;

import cn.hutool.json.JSONObject;
import com.lyf.result.Code;
import com.lyf.result.Result;
import redis.clients.jedis.Jedis;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/logout")
public class LogoutControll extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Jedis jedis = new Jedis("127.0.0.1",6379);
        jedis.auth("123456");

        jedis.del("id");
        jedis.del("loginname");


        Map<String,Object> map = new HashMap<>();
        Result result = new Result(Code.OK,null,"退出成功！");
        JSONObject jo = new JSONObject();

        map.put("result",result);
        jo.putAll(map);

        //响应到浏览器
        resp.getWriter().println(jo.toString());
    }
}
